package demo1;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-06
 * Time: 10:44
 */
public class TestDemo {

    public static  AtomicInteger atomicInteger = new AtomicInteger(0);
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                atomicInteger.getAndIncrement();
            }
        });
        t1.start();
        Thread t2 = new Thread(()->{
           for(int i =0;i<50000;++i){
               atomicInteger.getAndIncrement();
           }
        });
        t2.start();
        t1.join();
        t2.join();
        System.out.println(atomicInteger);
    }

}
